<?php
/**
 * 描述：船配-主页。
 * @final
 */
final class Exec_Ancillary_Index extends Exec
{
    public function Get()
    {
        #获取数据-经营模式
        View::Assign('Ancillary_Index_Business',DAO_BusinessModel::GetData());

        #最新采购信息
        $data=DB::GetRows('select * from supply order by ID desc limit 0,20');
        View::Assign('Ancillary_Index_Supply',$data);

        #最新企业信息
        $sql='select * from account ';
        $sql=$sql.'where not exists(select * from account_locked where account.Username=account_locked.Account) ';                      //不锁定
        $sql=$sql.'and not exists(select * from account_delete where account.Username=account_delete.Account) ';                        //没删除
        $sql=$sql.'and exists(select * from account_email_verification where account.Username=account_email_verification.Account) ';    //己通过邮件验证
        $sql=$sql.'order by ID desc limit 0,20 ';
        $data=DB::GetRows($sql);
        View::Assign('Ancillary_Index_Account',$data);

        #获取数据-强企推荐
        $sql='select * from account ';
        $sql=$sql.'where not exists(select * from account_locked where account.Username=account_locked.Account) ';                      //不锁定
        $sql=$sql.'and not exists(select * from account_delete where account.Username=account_delete.Account) ';                        //没删除
        $sql=$sql.'and exists(select * from account_email_verification where account.Username=account_email_verification.Account) ';    //己通过邮件验证
        $sql=$sql.'and exists(select * from account_powerful where account.Username=account_powerful.Account) ';                        //推荐为强企的
        $sql=$sql.'order by ID desc limit 0,6 ';
        $data=DB::GetRows($sql);
		foreach($data as &$row)
		{
			$row['Logo']=Config::PATH_RELATIVE_ATTACHMENT_LOGO.'/'.$row['Logo'];
		}		
        View::Assign('Ancillary_Index_AccountPowerful',$data);

        #获取数据-精品推荐
        $data=DB::GetRows('select * from supply where M_Recommend_Is=TRUE order by M_Recommend_Datetime desc,ID desc limit 0,6');
        foreach($data as &$row)
        {
            $row['ThumbnailPath']=Config::PATH_RELATIVE_ATTACHMENT_SUPPLY.'/'.$row['ThumbnailPath'];
        }
        View::Assign('Ancillary_Index_SuppliesRecommend',$data);

        #获取数据-主营行业
        $data=DB::GetRows('select * from trade where Identifying_Parent is NULL order by ID asc');
        foreach($data as &$row)
        {
            $row['Sub']=DB::GetRows('select * from trade where Identifying_Parent='.$row['Identifying'].' order by ID asc');
        }
        View::Assign('Ancillary_Index_Trade',array_chunk($data,3));

        #获取数据-产品类别
        $data=DB::GetRows('select * from category where Identifying_Parent is NULL order by ID asc');
        foreach($data as &$row)
        {
            $row['Sub']=DB::GetRows('select * from category where Identifying_Parent='.$row['Identifying'].' order by ID asc limit 0,5');
            foreach($row['Sub'] as &$rowSub)
            {
                $tmp=DB::GetRows('select count(*) as SupplyCount from supply where SubclassID='.$rowSub['Identifying']);
                if($tmp){
                    $rowSub['SupplyCount']=$tmp[0]['SupplyCount'];
                }
                else{
                    $rowSub['SupplyCount']=0;
                }
            }
        }
        View::Assign('Ancillary_Index_Category',$data);

        #获取数据
        $statistics=array
        (
            'AccountCount'=>NULL,
            'LatestAccount_ID'=>NULL,
            'LatestAccount_CompanyName'=>NULL,
            'SupplyCount'=>NULL,
            'LatestSupply_ID'=>NULL,
            'LatestSupply_Title'=>NULL
        );
        //企业
        $sql='select count(*) as AccountCount from account ';
        $sql=$sql.'where not exists(select * from account_locked where account.Username=account_locked.Account) ';                      //不锁定
        $sql=$sql.'and not exists(select * from account_delete where account.Username=account_delete.Account) ';                        //没删除
        $sql=$sql.'and exists(select * from account_email_verification where account.Username=account_email_verification.Account) ';    //己通过邮件验证
        $sql=$sql.'order by ID desc limit 0,1';
        $data=DB::GetRows($sql);
        if($data)
        {
            $statistics['AccountCount']=$data[0]['AccountCount'];
        }
        $sql='select ID,CompanyName from account ';
        $sql=$sql.'where not exists(select * from account_locked where account.Username=account_locked.Account) ';                      //不锁定
        $sql=$sql.'and not exists(select * from account_delete where account.Username=account_delete.Account) ';                        //没删除
        $sql=$sql.'and exists(select * from account_email_verification where account.Username=account_email_verification.Account) ';    //己通过邮件验证
        $sql=$sql.'order by ID desc limit 0,1';
        $data=DB::GetRows($sql);
        if($data)
        {
            $statistics['LatestAccount_ID']=$data[0]['ID'];
            $statistics['LatestAccount_CompanyName']=$data[0]['CompanyName'];
        }
        //产品
        $data=DB::GetRows('select count(*) as SupplyCount from supply order by ID desc');
        if($data)
        {
            $statistics['SupplyCount']=$data[0]['SupplyCount'];
        }
        $data=DB::GetRows('select ID,Title from supply order by ID desc');
        if($data)
        {
            $statistics['LatestSupply_ID']=$data[0]['ID'];
            $statistics['LatestSupply_Title']=$data[0]['Title'];
        }
        View::Assign('Statistics',$statistics);


        #渲染输出
        View::Display('ancillary/index.tpl');
    }
}
?>